home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 026a / db3procs.zip / PROCS.PRG < prev    next >
Text File  |  1991-02-18  |  19KB  |  581 lines

  1. *---> Procedure File:   Procs.prg
  2. *---> Author:           Chris K. Kaufman
  3. *---< Last#Update:      18-Feb-91
  4. *---> Purpose:          Demonstration of useful procedures
  5. *---> Called by:        Main.prg
  6. *--.0,Qsds:             Menu.dbf, Menu.ndx, Sample.dbf, Sample.ndx
  7.  
  8. *---> This procedure file contains the following useful utilities
  9. *---> menu      Displays a popup menu window using parameters 
  10. *--->           stored in menu.dbf, choices can be made by pressing
  11. *--->           the key corresponding to a menu item or by using
  12. *--->           the arrow keys to move the selection bar.
  13. *---> errormsg  Displays an error message on line 24 of the
  14. *--->           screen and waits for a key press.
  15. *---> Title     Displays a centered title on line 0 of the screen.
  16. *---> blankmenu Blanks the last menu displayed.
  17. *---> clrwindow Clears a window on the screen
  18. *---> dispinst  Displays instructions on line 23 of the screen
  19. *--->           in the same color as the last menu.
  20. *---> picklist  Displays a list of items from the currently selected
  21. *--->           database to choose from.
  22.  
  23. procedure menu
  24. *---> Menu displays popup menu.  Arrow keys allow selection bar to be scrolled,
  25. *---> Pressing the first or key letter of any option moves selection bar to
  26. *---> that option.  Pressing Enter returns selection number to calling 
  27. *---> procedure.  Other keystrokes are ignored.  
  28. *---> menuscrn is name of menu, used as index into menu database.
  29. *---> selection is option command to return to calling procedure.
  30. parameters mscrn, selection
  31. *---> get menu information
  32. select 9
  33. seek mscrn
  34. *---> check for menu system error
  35. if found()
  36.   *---> menu found
  37.   *---> get menu colors
  38.   mcolormenu = menu->colormenu
  39.   mcolorbar  = menu->colorbar
  40.   mcolorbord = menu->colorbord
  41.   *---> draw border
  42.   set color to &mcolorbord
  43.   @top-1,left-1 to top+numoptions,left+optwidth double
  44.   *---> display options
  45.   set color to &mcolormenu
  46.   selection = 0
  47.   do while selection < numoptions
  48.     textnorm = 'option'+ltrim(str(selection))
  49.     @top+selection,left say substr(&textnorm,1,optwidth)
  50.     selection = selection+1
  51.   enddo
  52.   *---> highlight first menu selection
  53.   set color to &mcolorbar
  54.   @top,left say substr(option0,1,optwidth)
  55.   *---> display first menu description
  56.   @23,0 say descr0
  57.   *---> initialize loop variables
  58.   response = 0
  59.   previous = 0
  60.   selection = 0
  61.   *---> top of loop
  62.   do while response <> 13
  63.     response = 0
  64.     *---> wait for keypress
  65.     do while response = 0
  66.       response = inkey()
  67.     enddo
  68.     *---> remember previous selection
  69.     previous = selection
  70.     *---> process keypress
  71.     do case
  72.       case response = 24
  73.         *---> down arrow
  74.         selection = mod(selection+1,numoptions)
  75.       case response = 5
  76.         *---> up arrow
  77.         selection = mod(selection+numoptions-1,numoptions)
  78.       case response >= 0
  79.         *---> not an arrow key, check for option letters
  80.         *---> convert to uppercase character
  81.         chrresp = upper(chr(response))
  82.         *---> find location in option string, location-1 is selection
  83.         selection = at(chrresp,optstring)-1
  84.         if (selection = -1) .or. (selection >= numoptions)
  85.           *---> selection not found, restore previous
  86.           selection = previous
  87.         endif
  88.       otherwise
  89.         *---> function keys return negative values
  90.     endcase
  91.     if selection <> previous
  92.       *---> move selection bar
  93.       *---> write previous menu selection in normal (menu) color
  94.       textnorm = 'option'+ltrim(str(previous))
  95.       set color to &mcolormenu
  96.       @top+previous,left say substr(&textnorm,1,optwidth)
  97.       *---> write new menu selection in highlighted (bar) color
  98.       texthigh = 'option'+ltrim(str(selection))
  99.       set color to &mcolorbar
  100.       @top+selection,left say substr(&texthigh,1,optwidth)
  101.       texthigh = 'descr'+ltrim(str(selection))
  102.       @23,0 say &texthigh
  103.     endif
  104.   enddo
  105. else
  106.   *---> menu not found 
  107.   do errormsg with 'Menu not available.  Press any key to continue.'
  108.   *---> return -1 as menusel
  109.   menusel = -1
  110. endif
  111. *---> return to calling procedure.
  112. select 1
  113. return
  114.  
  115. procedure errormsg
  116. *---> display error message on last line, wait for keypress.
  117. *---> message is string to display
  118. parameters message
  119. *---> display message in yellow on red, centered, at bottom of screen
  120. set color to gr+/r
  121. @24,int(40-len(message)/2) say message
  122. *---> wait for keypress
  123. do while inkey() = 0
  124. enddo
  125. *---> blank error
  126. set color to
  127. @24,0 say space(80)
  128. *---> return to calling procedure
  129. return
  130.  
  131. procedure title
  132. *---> display title at top of screen
  133. parameters title
  134. set color to gr+/n
  135. @0,0 say space(80)
  136. @0,40-int(len(title)/2) say title
  137. return
  138.  
  139. procedure blankmenu
  140. *---> blank the last menu displayed
  141. do clrwindow with menu->top-1,menu->left-1,menu->top+menu->numoptions,menu->left+menu->optwidth
  142. return
  143.  
  144. procedure clrwindow
  145. *---> blank window 
  146. parameters top,left,bottom,right
  147. set color to
  148. blankline = space(right-left+1)
  149. ptr = top
  150. do while ptr <= bottom
  151.   @ ptr,left say blankline
  152.   ptr = ptr+1
  153. enddo
  154. return
  155.  
  156. procedure dispinst
  157. parameters message
  158. *---> set color to match menu bar
  159. color = menu->colorbar
  160. set color to &color
  161. *---> blank old message, display new message
  162. @23,0 say space(80)
  163. @23,0 say message
  164. return
  165.  
  166. procedure picklist
  167. *---> picklist displays a list of string expressions and allows the user to
  168. *---> select one string to be returned.  up and down arrows allow scrolling
  169. *---> dbf used is in current select area
  170. parameters  strexpr, mcolormenu, mcolorbar, mcolorbord, top, left, numoptions
  171. *---> draw border
  172. set color to &mcolormenu
  173. @ top-1,left-1 to top+numoptions,left+len(&strexpr) double
  174. *---> initialize pointers
  175. numsel = 0
  176. offset = 0
  177. *---> initialize loop variables
  178. response = 0
  179. previous = 0
  180. selection = 0
  181. *---> display options
  182. do displist with selection
  183. *---> top of loop
  184. do while response <> 13 .and. response <> 27
  185.   response = 0
  186.   *---> wait for keypress
  187.   do while response = 0
  188.     response = inkey()
  189.   enddo
  190.   *---> process keypress
  191.   do case
  192.     case response = 3
  193.       *---> page down
  194.       if selection = numsel - 1
  195.         *---> at bottom of window
  196.         if numsel = numoptions
  197.           *---> window is full, scroll
  198.           offset = offset + numoptions - 1
  199.           selection = 0
  200.         endif
  201.       else
  202.         *---> move to bottom of window
  203.         selection = numsel - 1
  204.       endif
  205.       do displist with selection
  206.     case response = 5
  207.       *---> up arrow
  208.       do moveup
  209.     case response = 18
  210.       *---> page up
  211.       if selection = 0
  212.         if offset < numoptions - 1
  213.           offset = 0
  214.           selection = 0
  215.         else
  216.           offset = offset - numoptions + 1
  217.         endif
  218.       else
  219.         offset = offset + numsel - numoptions
  220.         selection = 0
  221.       endif
  222.       do displist with selection
  223.     case response = 24
  224.       *---> down arrow
  225.       do movedown
  226.     otherwise
  227.       *---> ignore key
  228.   endcase
  229. enddo
  230. if response = 27
  231.   *---> picklist terminated with ESC
  232.   *---> return eof()
  233.   if .not. eof()
  234.     go bottom
  235.     skip
  236.   endif
  237. endif
  238. *---> remove picklist
  239. do clrwindow with top-1,left-1,top+numoptions,left+len(&strexpr)
  240. *---> return to calling procedure.
  241. return
  242.  
  243. procedure displist
  244. *---> numsel is number of selections actually available
  245. *---> point to string expression at record number offset.
  246. parameters hisel
  247. goto top
  248. skip offset
  249. numsel = 0
  250. if eof()
  251. *---> check for empty list
  252.   do errormsg with 'No options to display.  Press any key to continue.'
  253. else
  254.   *---> display string expressions until numoptions have been displayed 
  255.   *---> or end of file is reached.
  256.   do while (numsel < numoptions) .and. (.not. eof())
  257.     if numsel = hisel
  258.       *---> highlight menu option
  259.       set color to &mcolorbar
  260.     else
  261.       *---> normal option
  262.       set color to &mcolormenu
  263.     endif
  264.     @top+numsel, left say &strexpr
  265.     *---> move pointer
  266.     skip
  267.     numsel = numsel + 1
  268.   enddo
  269.   *---> restore pointer to offset
  270.   skip hisel-numsel
  271.   *---> if end of list found blank remaining entries
  272.   if numsel < numoptions
  273.     set color to &mcolormenu
  274.     blankopt = space(len(&strexpr))
  275.     i = numsel
  276.     do while i < numoptions
  277.       @top+i,left say blankopt
  278.       i = i+1
  279.     enddo
  280.   endif
  281. endif
  282. return
  283.  
  284. procedure movedown
  285. if selection < numsel-1
  286.   *---> display old selection in normal color
  287.   set color to &mcolormenu
  288.   @top+selection, left say &strexpr
  289.   *---> move pointers
  290.   selection = selection + 1
  291.   skip
  292.   *---> display new selection in highlit color
  293.   set color to &mcolorbar
  294.   @top+selection, left say &strexpr
  295. else
  296.   *---> at bottom of window
  297.   *---> only scroll window if window is full
  298.   if numsel = numoptions
  299.     offset = offset+selection
  300.     selection = 0
  301.     do displist with selection
  302.   endif
  303. endif
  304. return
  305.  
  306. procedure moveup
  307. if selection > 0
  308.   *---> display old selection in normal color
  309.   set color to &mcolormenu
  310.   @top+selection, left say &strexpr
  311.   *---> move pointers
  312.   selection = selection - 1
  313.   skip -1
  314.   *---> display new selection in highlit color
  315.   set color to &mcolorbar
  316.   @top+selection, left say &strexpr
  317. else
  318.   *---> at top of window, scroll 1 page and leave bar at bottom of window
  319.   if offset < numoptions-1
  320.     *---> too close to top of file, can't scroll full page
  321.     selection = offset
  322.     offset = 0
  323.   else
  324.     *---> scroll full page
  325.     offset = offset-numoptions+1
  326.     selection = numoptions-1
  327.   endif
  328.   do displist with selection
  329. endif
  330. return
  331.  
  332. procedure disphelp
  333. *---> display help information
  334. set color to r/n
  335. @ 14,9 to 22,70 double
  336. set color to gr+/n
  337. @ 16, 10 say 'Move the menu selection bar with the cursor up and down keys'
  338. @ 17, 10 say 'or by pressing the first capitalized letter of an option.   '
  339. @ 18, 10 say 'Press the Enter key to activate the selection.  The bottom  '
  340. @ 19, 10 say 'two lines of the screen display descriptions of menu options'
  341. @ 20, 10 say 'and error messages.  Each menu item displays help on the    '
  342. @ 21, 10 say 'corresponding procedure.                                    '
  343. do dispinst with 'Menu descriptions and instructions display here.'
  344. do errormsg with 'Error messages display here.  Press any key to continue.'
  345. set color to
  346. @14,0 clear
  347. return
  348.  
  349. *---> The following procedures are called by Main.prg to explain/demonstrate
  350. *---> procedures defined above.
  351.  
  352. procedure menuinf
  353. *---> display information on menu
  354. do dispinst with 'Menu procedure information.'
  355. *---> display first bit of info.
  356. set color to gr+/n
  357. @15,0
  358. text
  359. The menu procedure is called with two parameters, the menu screen name and the
  360. variable that the menu selection will be returned as.  All other information
  361. is stored in menu.dbf in select area 9.  After a menu choice is made the select
  362. area is set to one, and selection number 0..n is returned.
  363. endtext
  364. do errormsg with 'Press any key to continue...'
  365. do clrwindow with 15,0,22,79
  366. *---> display next bit of info.
  367. set color to gr+/n
  368. @15,0 
  369. text
  370. The menu options that can be set in the menu.dbf file are the location of the
  371. upper left hand corner of the menu, the colors of the menu, menu bar and menu
  372. border, the number of options in the menu (1..20), the width of the menu
  373. (1..20), the prompt for each menu choice, the description of each menu choice
  374. that is displayed on line 23, and the characters that will be accepted to
  375. select each of the menu items. 
  376. endtext
  377. do errormsg with 'Press any key to continue...'
  378. do clrwindow with 15,0,22,79
  379. *---> display next bit of info.
  380. set color to gr+/n
  381. @15,0 
  382. text
  383. The code for calling a menu is:
  384. menusel = 0                          >>> initialize parameter to be passed
  385. do menu with 'menu name ',menusel    >>> 'menu name ' is 10 character key
  386.   do case                                       into menu.dbf
  387.   case menusel=0                     >>> process menu options 0..n
  388.     ...
  389.   endcase
  390. endtext
  391. do errormsg with 'Press any key to continue...'
  392. do clrwindow with 15,0,22,79
  393. *---> display next bit of info.
  394. set color to gr+/n
  395. @15,0 
  396. text
  397. Notes:  First menu option is 0, if you have 10 options they are 0..9
  398.         After calling a menu you are returned to select area 1
  399.         Window size is 2 greater than numoptions x optionwidth to allow
  400.                 for border around window.
  401.         For best results use only 3 color for menu, menubar, and menuborder.
  402.                 for example: C1/C2, C1/C3 & C3/C2 or C1/C2, C2/C3, & C3/C1
  403. endtext
  404. do errormsg with 'Press any key to display a sub-menu'
  405. subsel = 0
  406. do title with 'S U B   M E N U  - Select an option and press <Enter>.'
  407. do menu with 'sub menu 1', subsel
  408. do blankmenu
  409. do clrwindow with 15,0,22,79
  410. return
  411.  
  412. procedure errmsginf
  413. *---> display information on errormsg procedure
  414. do dispinst with 'Errormsg procedure information.'
  415. *---> display first bit of info.
  416. set color to gr+/n
  417. @15,0
  418. text
  419. The errormsg procedure is called with one parameter, the error message to
  420. display.  The message is displayed centered on line 24 in yellow on red until a
  421. key is pressed.  For example:
  422.  
  423.         do errormsg with 'Sample Error Message.  Press any key to continue.'
  424.  
  425. will display as shown below.        
  426. endtext
  427. do errormsg with 'Sample Error Message.  Press any key to continue.'
  428. do clrwindow with 15,0,22,79
  429. return
  430.  
  431. procedure blmenuinf
  432. *---> display information on blankmenu procedure
  433. do dispinst with 'Blankmenu procedure information.'
  434. *---> display first bit of info.
  435. set color to gr+/n
  436. @15,0
  437. text
  438. The blankmenu procedure blanks the previous menu (paints it black).
  439. No parameters are passed.  The syntax is:
  440.  
  441.         do blankmenu
  442. endtext
  443. do errormsg with 'Press any key to blank the menu.'
  444. do blankmenu
  445. do clrwindow with 15,0,22,79
  446. *---> display the next bit of info.
  447. set color to gr+/n
  448. @15,0
  449. text
  450. The menu has been blanked.        
  451. endtext
  452. do errormsg with 'Press any key to return to the menu.'
  453. do clrwindow with 15,0,22,79
  454. return
  455.  
  456. procedure titleinf
  457. *---> display information on title procedure
  458. do dispinst with 'Title procedure information.'
  459. *---> display first bit of info.
  460. set color to gr+/n
  461. @15,0
  462. text
  463. The title procedure is called with one parameter: the title to be displayed.
  464. The title is displayed centerered on line 0 in yellow.  An example follows:
  465.  
  466.         do title with 'This is a new title line.'
  467. endtext
  468. do errormsg with 'Press any key to display the new title.'
  469. do title with 'This is a new title line.'
  470. do clrwindow with 15,0,22,79
  471. *---> display the next bit of info.
  472. set color to gr+/n
  473. @15,0
  474. text
  475. The new title is displayed.
  476. endtext
  477. do errormsg with 'Press any key to return to the menu.'
  478. do clrwindow with 15,0,22,79
  479. return
  480.  
  481. procedure clrwininf
  482. *---> display information on clrwindow procedure
  483. do dispinst with 'Clrwindow procedure information.'
  484. *---> display first bit of info.
  485. set color to gr+/n
  486. @15,0
  487. text
  488. The clrwindow procedure clears (paints black) a rectangular block of text.
  489. The parameters passed are coordinates of the top left and bottom right
  490. corners of the block.  For example, to clear a block of text from 10,35 to
  491. 17,45 the command:
  492.         do clrwindow with 10,35,17,45
  493. would be used.
  494. endtext
  495. do errormsg with 'Press any key to clear a window from 10,35 to 17,45.'
  496. do clrwindow with 10,35,17,45
  497. *---> display the next bit of info.
  498. do dispinst with 'The window has been cleared.'
  499. do errormsg with 'Press any key to return to the menu.'
  500. do clrwindow with 15,0,22,79
  501. return
  502.  
  503. procedure dinstinf
  504. *---> display information on dispinst procedure
  505. do dispinst with 'Dispinst procedure information.'
  506. *---> display first bit of info.
  507. set color to gr+/n
  508. @15,0
  509. text
  510. The dispinst procedure displays instructions on line 24 in the current menubar
  511. colors.  One parameter is passed: the message to be displayed.
  512. the format is:
  513.         do dispinst with 'dispinst display information on this line.'
  514. endtext
  515. do errormsg with 'Press any key to display the above message.'
  516. do dispinst with 'dispinst display information on this line.'
  517. do clrwindow with 15,0,22,79
  518. *---> display the next bit of info.
  519. set color to gr+/n
  520. @15,0
  521. text
  522. The new instruction line has been displayed.
  523. endtext
  524. do errormsg with 'Press any key to return to the menu.'
  525. do clrwindow with 15,0,22,79
  526. return
  527. procedure plistinf
  528. *---> display information on picklist procedure
  529. do dispinst with 'Picklist procedure information.'
  530. *---> display first bit of info.
  531. set color to gr+/n
  532. @15,0
  533. text
  534. The picklist procedure allows the user to pick a record out of a database.  A
  535. window is displayed with a field or an expression involving one or more fields.
  536. The user can scroll up and down through the list using the up/down cursor keys
  537. and the page up/page down keys.  A record in the database is chosen by pressing
  538. enter when the desired information is highlighted in the window.  The procedure
  539. returns with the selected record current.  If ESC is pressed the procedure
  540. returns EOF().
  541. endtext
  542. do errormsg with 'Press any key to continue...'
  543. do clrwindow with 15,0,22,79
  544. *---> display the next bit of info.
  545. set color to gr+/n
  546. @15,0
  547. text
  548. When the procedure is called the parameters passed are the string expression to
  549. display, the colors to use, the location of the top left corner of the window,
  550. and the number of selections to display in the window.  The database must be in
  551. the current selected area.  Filters and indexes may be active.
  552. IMPORTANT:  The string expression must be of constant length.
  553. endtext
  554. do errormsg with 'Press any key to continue...'
  555. do clrwindow with 15,0,22,79
  556. *---> display the next bit of info.
  557. set color to gr+/n
  558. @15,0
  559. text
  560. Sample code for using a picklist follows:
  561.  
  562.         use sample index sample                                             
  563.         do picklist with 'last_name+", "+first_name+" "+middl_init+"."', 
  564.                  'w+/b', 'w+/r', 'r/b', 7, 1, 7
  565.                  
  566. NOTE: The previous line was split to fit on the display.
  567. endtext
  568. do errormsg with 'Press any key to display picklist.'
  569. do clrwindow with 15,0,22,79
  570. use sample index sample
  571. do picklist with 'last_name+", "+first_name+" "+middl_init+"."', 'w+/b', 'w+/r', 'r/b', 7, 1, 7
  572. if eof()
  573.   do dispinst with 'You pressed ESC to leave the pick list.'
  574. else
  575.   do dispinst with 'You selected '+trim(first_name)+' '+middl_init+'. '+last_name
  576. endif
  577. use
  578. do errormsg with 'Press any key to return to the main menu.'
  579. return
  580.  
  581.